
jQuery(function($){    
    
    var date = new Date();
    var d = date.getDate();
    var m = date.getMonth();
    var y = date.getFullYear();
    
    if( $("#user-calendar").size() > 0 ){
        $("#user-calendar").fullCalendar({
            height: 500
            ,header: {
                left: '',
                center: 'title',
                right: 'prev,next today'
            }
            ,eventClick: function(calEvent, jsEvent, view) {
               var prev_click_id = $("#prev-click-id").html();

               if(prev_click_id == "" || (prev_click_id != "" && prev_click_id != calEvent.id)) {
                   event_view_table_init();
                   $("td:eq(1)",$("#user-event-view-table tr:eq(0)")).html(calEvent.title);               
                   $("td:eq(1)",$("#user-event-view-table tr:eq(1)")).html(calEvent.start.formatDate("yyyy년 MM월 dd일 HH시 mm분 ss초"));
                   $("td:eq(1)",$("#user-event-view-table tr:eq(2)")).html(calEvent.end.formatDate("yyyy년 MM월 dd일 HH시 mm분 ss초"));
                   $("td:eq(1)",$("#user-event-view-table tr:eq(3)")).html(calEvent.location);
                   $("td:eq(1)",$("#user-event-view-table tr:eq(4)")).html(calEvent.content);              
                   $("#user-event-view").show();
               }else{
                   $("#user-event-view").toggle();
               }
               $("#prev-click-id").html(calEvent.id);
            }
            ,editable: false
            ,events: './wp-content/plugins/epart-schedule/admin/schedule-admin-data.php?cateno=' + cateno
            ,columnFormat: {
                    month: "dddd"
                    ,week: 'ddd M/d'
                    ,day: 'dddd M/d'
            }
            ,titleFormat: {
                    month: 'yyyy년 MMMM',
                    week: "yyyy년 MMMM d[ yyyy]{ '&#8212;'[ MMM] d}",
                    day: 'yyyy, MMMM d'
            }
            ,timeFormat: "TTh:mm"
            ,monthNames: ["1월", "2월", "3월", "4월", "5월", "6월", "7월", "8월", "9월", "10월", "11월", "12월"]
            ,monthNamesShort: ["1월", "2월", "3월", "4월", "5월", "6월", "7월", "8월", "9월", "10월", "11월", "12월"]
            ,dayNames: ["일요일", "월요일", "화요일", "수요일", "목요일", "금요일", "토요일"]
            ,dayNamesShort: ["일", "월", "화", "수", "목", "금", "토"]
            ,dragOpacity: 0.8
            ,theme:true

        });
    }
    // 뷰 초기화
    function event_view_table_init() {
         $("td:eq(1)",$("#user-event-view-table tr:eq(0)")).html("");
         $("td:eq(1)",$("#user-event-view-table tr:eq(1)")).html("");
         $("td:eq(1)",$("#user-event-view-table tr:eq(2)")).html("");
         $("td:eq(1)",$("#user-event-view-table tr:eq(3)")).html("");
         $("td:eq(1)",$("#user-event-view-table tr:eq(4)")).html("");         
    }

    // 카테고리 select box
    $("#user-sk-cateno").change(function(){
        var sk_cateno = $(this).val();
        if(sk_cateno != ""){
            $("#user-search-category-form").attr("action",schedule_user_url+"cateno/"+sk_cateno);
        }else{
            $("#user-search-category-form").attr("action",schedule_user_url);
        }
    });
});


